package cn.broadin.app.hotel.app;

import cn.broadin.app.hotel.SettingsActivity;
import cn.broadin.app.hotel.util.XSound;
import cn.broadin.app.hotel.util.XUtils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.support.multidex.MultiDexApplication;
import android.text.TextUtils;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.tencent.mmkv.MMKV;

/**
 * 自定义全局变量
 *
 * @author long
 * @version 1.0.0
 * @date 2015年9月24日上午10:18:48
 */
public class AppContext extends MultiDexApplication {

	public static XSound sound;
	public static AppContext app;
	public String productInfo = null;
	public String chipsInfo = null;
	public String AuthFlag = null;
	public String pingResult = null;
	public String indexVideoUrl = null;
	public String startVideoUrl = null;
	public String hotelsIntroUrl = null;


	/**
	 * 设备是否授权
	 */
	public boolean deviceAuthFlag;

	public static AppContext getInstance() {
		return app;
	}
	public String getProductInfo() {
		return productInfo;

	}

	public String getChipsInfo() {
		return chipsInfo;

	}

	public String getAuthFlag() {
		return AuthFlag;
	}

	public String getpingResult() {
		return pingResult;
	}

	public String getStartVideoUrl() {
		return startVideoUrl;
	}
	public String getIndexVideoUrl() {
		return indexVideoUrl;
	}

	public String getHotelsIntroUrl() {
		return hotelsIntroUrl;
	}

	public void setProductInfo(String productInfo) {
		this.productInfo = productInfo;
	}

	public void setChipsInfo(String chipsInfo) {
		this.chipsInfo = chipsInfo;
	}

	public void setpingResult(String pingResult) {
		this.pingResult = pingResult;
	}

	public void setAuthFlag(String AuthFlag) {
		this.AuthFlag = AuthFlag;
	}

	public void setStartVideoUrl(String startVideoUrl) {
		this.startVideoUrl = startVideoUrl;
	}

	public void setIndexVideoUrl(String indexVideoUrl) {
		this.indexVideoUrl = indexVideoUrl;
	}

	public void setHotelsIntroUrl(String hotelsIntroUrl) {
		this.hotelsIntroUrl = hotelsIntroUrl;
	}

	/**
	 * @see android.app.Application#onCreate()
	 * @exception
	 * @author long
	 * @since 1.0.0
	 * @date 2015年9月24日 上午10:19:26
	 */
	@Override
	public void onCreate() {
		super.onCreate();

		app = this;

		sound = new XSound(getApplicationContext());
		//sound.loadSfx(R.raw.move_left, 0);
		//sound.loadSfx(R.raw.move_right, 0);
		//sound.loadSfx(R.raw.page_change, 1);

		// 初始化配置数据
		initSettings();

		MMKV.initialize(this);
		Fresco.initialize(this);
	}

	/**
	 * 初始化系统配置参数
	 *
	 * @author   long
	 * @return void
	 * @exception
	 * @author   long
	 * @since 1.0.0
	 * @date 2016年1月4日 上午11:29:08
	 */
	private void initSettings(){
		String value = XUtils.getSharedPreferenceConfig(getApplicationContext(), SettingsActivity.KEY_HOTEL_ROOM_URL);
		if(TextUtils.isEmpty(value)){
			SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
			Editor editor = sharedPref.edit();
			editor.putString(SettingsActivity.KEY_HOTEL_ROOM_URL, SettingsActivity.VALUE_HOTEL_ROOM_URL);
//	    	editor.putString(SettingsActivity.KEY_HOTEL_INTRO_URL, SettingsActivity.VALUE_HOTEL_INTRO_URL);
//	    	editor.putString(SettingsActivity.KEY_HOTEL_LIVE_URL, SettingsActivity.VALUE_HOTEL_LIVE_URL);
			editor.commit();
		}
	}

	public void exitApp(Context mContext){
		System.exit(0);
	}
}